(define (empty-env) 
    `()
)


(define (empty-env? env) 
    (null? env)
)


(define (extend-env var val env)
    (cons 
        (list var val) 
        env
    )
)


(define (apply-env env search-var)
    (if (empty-env? env)
        (report-no-binding-found)
        (let
            (
                (saved-var (caar env))
                (saved-val (cadar env))
                (saved-env (cdr env))
            )
            (if (eqv? search-var saved-var)
                saved-val
                (apply-env saved-env search-var)
            )
        )
    )
)


(define (report-no-binding-found search-var)
    (eopl:error ’apply-env "No binding for ~s" search-var)
)


(define (report-invalid-env env)
    (eopl:error ’apply-env "Bad environment: ~s" env)
)
